import { IPSDataEntity } from '../ipsdata-entity';
import { IPSDEField } from '../defield/ipsdefield';
import { IPSDENotifyTarget } from './ipsdenotify-target';
import { IPSSysMsgTarget } from '../../msg/ipssys-msg-target';
import { PSModelObjectImpl } from '../../psmodel-object-impl';

export class PSDENotifyTargetImpl extends PSModelObjectImpl implements IPSDENotifyTarget {
  get codeName(): string {
    return this.M.codeName;
  }

  get dynaModelFilePath(): string {
    return this.M.dynaModelFilePath;
  }

  get filter(): string {
    return this.M.filter;
  }

  get memo(): string {
    return this.M.memo;
  }

  get name(): string {
    return this.M.name;
  }

  protected pssysmsgtar: IPSSysMsgTarget | null = null;

  getPSSysMsgTarget(): IPSSysMsgTarget | null {
    if (this.pssysmsgtar != null) return this.pssysmsgtar;
    const value = this.M.getPSSysMsgTarget;
    if (value == null) {
      return null;
    }
    this.pssysmsgtar = this.getPSModel4('msg.IPSSysMsgTarget', value, 'getPSSysMsgTarget') as IPSSysMsgTarget;
    return this.pssysmsgtar;
  }

  get psSysMsgTarget(): IPSSysMsgTarget | null {
    return this.getPSSysMsgTarget();
  }

  getPSSysMsgTargetMust(): IPSSysMsgTarget {
    const value = this.getPSSysMsgTarget();
    if (value == null) {
      throw new Error('未指定系统消息目标');
    }
    return value;
  }

  protected tarpsdefield: IPSDEField | null = null;

  getTargetPSDEField(): IPSDEField | null {
    if (this.tarpsdefield != null) return this.tarpsdefield;
    const value = this.M.getTargetPSDEField;
    if (value == null) {
      return null;
    }
    const ipsdataentity = this.getParentPSModelObject('dataentity.IPSDataEntity') as IPSDataEntity;
    if (ipsdataentity != null) {
      this.tarpsdefield = ipsdataentity.findPSDEField(value);
    }
    return this.tarpsdefield;
  }

  get targetPSDEField(): IPSDEField | null {
    return this.getTargetPSDEField();
  }

  getTargetPSDEFieldMust(): IPSDEField {
    const value = this.getTargetPSDEField();
    if (value == null) {
      throw new Error('未指定目标标识值存储属性');
    }
    return value;
  }

  get targetType(): 'DEFIELD' | 'SYSMSGTARGET' | 'USER' | 'USER2' {
    return this.M.targetType;
  }

  protected tartypepsdefield: IPSDEField | null = null;

  getTargetTypePSDEField(): IPSDEField | null {
    if (this.tartypepsdefield != null) return this.tartypepsdefield;
    const value = this.M.getTargetTypePSDEField;
    if (value == null) {
      return null;
    }
    const ipsdataentity = this.getParentPSModelObject('dataentity.IPSDataEntity') as IPSDataEntity;
    if (ipsdataentity != null) {
      this.tartypepsdefield = ipsdataentity.findPSDEField(value);
    }
    return this.tartypepsdefield;
  }

  get targetTypePSDEField(): IPSDEField | null {
    return this.getTargetTypePSDEField();
  }

  getTargetTypePSDEFieldMust(): IPSDEField {
    const value = this.getTargetTypePSDEField();
    if (value == null) {
      throw new Error('未指定目标类型值存储属性');
    }
    return value;
  }

  get userCat(): string {
    return this.M.userCat;
  }

  get userTag(): string {
    return this.M.userTag;
  }

  get userTag2(): string {
    return this.M.userTag2;
  }

  get userTag3(): string {
    return this.M.userTag3;
  }

  get userTag4(): string {
    return this.M.userTag4;
  }

  get cls(): string {
    return 'PSDENotifyTargetImpl';
  }

  instanceof(cls: string): boolean {
    if (cls == 'dataentity.notify.IPSDENotifyTarget') return true;
    return super.instanceof(cls);
  }
}
